#!/usr/bin/python
import snakekit
import sys
import getopt

def usage():
    print """
Usage: macvf -m <mac_address> [options]

Mandatory arguments:
-m                      MAC address formated as 00:0a:45:8f:90:ad
                        Hex can be lower case or upper.

Optional arguments:

-h                      Show help.
-f <file_name>          Use an external vendor names file.
-p                      Print built-in vendor names.
-n <name>               Print vendors matching name.

"""
    sys.exit(0)

def print_vendors():
    for i in snakekit.MacVendorFinder().get_builtin_vendor_list():
        if i.strip() != "":
            print i
    sys.exit(0)
    
def print_matching_vendors(vendor_name):
    print "Finding vendors matching: %s" % vendor_name
    for i in snakekit.MacVendorFinder().get_vendor_match(vendor_name):
        print i
    sys.exit(0)
    
try:
    opt, arg = getopt.gnu_getopt(sys.argv[1:], "m:hf:pn:")
except: usage()

mac = ""
ouifile = ""
    
for i,v in opt:
    if i == "-h":
        usage()
    elif i == "-m":
        mac = v
    elif i == "-f":
        ouifile = v
    elif i == "-p":
        print_vendors()
    elif i == "-n":
        vendor_name = v
        print_matching_vendors(v)
    

if mac == '':
    usage()

if ouifile != "":
    finder = snakekit.MacVendorFinder(mac, vendor_list=ouifile)
else:
    finder = snakekit.MacVendorFinder(mac)

finder.find()
print "NIC Vendor: %s" % finder.vendor
